{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "befffeef",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "DatetimeIndex(['2025-01-01', '2025-01-02', '2025-01-03', '2025-01-04',\n",
      "               '2025-01-05', '2025-01-06'],\n",
      "              dtype='datetime64[ns]', freq='D')\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "from IPython.display import display\n",
    "\n",
    "s = pd.Series([1, 3, 6, np.nan, 44, 1])  # np.nan => NaN\n",
    "\n",
    "dates = pd.date_range('20250101', periods=6)\n",
    "print(dates)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "8906ec5b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                   a         b         c         d\n",
      "2025-01-01 -0.973137  0.733602  2.024262  1.006747\n",
      "2025-01-02 -1.116114 -0.489079  0.860994  0.759232\n",
      "2025-01-03  0.629125 -0.064448 -1.541185  1.004417\n",
      "2025-01-04  0.735516  0.345721 -0.005220  0.014434\n",
      "2025-01-05  0.163124  1.600174 -0.064066 -0.024594\n",
      "2025-01-06  1.669308  0.377109 -1.680497 -1.543397\n"
     ]
    }
   ],
   "source": [
    "df = pd.DataFrame(np.random.randn(6, 4), index=dates, columns=[\"a\", \"b\", \"c\", \"d\"])\n",
    "print(df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "35a27a81",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   0  1   2   3\n",
      "0  0  1   2   3\n",
      "1  4  5   6   7\n",
      "2  8  9  10  11\n"
     ]
    }
   ],
   "source": [
    "df1 = pd.DataFrame(np.arange(12).reshape((3, 4)))\n",
    "print(df1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "e27b8129",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "     A          B    C  D      E    F\n",
      "0  1.0 2013-01-02  1.0  3   test  foo\n",
      "1  1.0 2013-01-02  1.0  3  train  foo\n",
      "2  1.0 2013-01-02  1.0  3   test  foo\n",
      "3  1.0 2013-01-02  1.0  3  train  foo\n",
      "--------------------\n",
      "Index(['A', 'B', 'C', 'D', 'E', 'F'], dtype='object')\n",
      "[[1.0 Timestamp('2013-01-02 00:00:00') 1.0 3 'test' 'foo']\n",
      " [1.0 Timestamp('2013-01-02 00:00:00') 1.0 3 'train' 'foo']\n",
      " [1.0 Timestamp('2013-01-02 00:00:00') 1.0 3 'test' 'foo']\n",
      " [1.0 Timestamp('2013-01-02 00:00:00') 1.0 3 'train' 'foo']]\n",
      "\n",
      "\n",
      "                     0                    1                    2  \\\n",
      "A                  1.0                  1.0                  1.0   \n",
      "B  2013-01-02 00:00:00  2013-01-02 00:00:00  2013-01-02 00:00:00   \n",
      "C                  1.0                  1.0                  1.0   \n",
      "D                    3                    3                    3   \n",
      "E                 test                train                 test   \n",
      "F                  foo                  foo                  foo   \n",
      "\n",
      "                     3  \n",
      "A                  1.0  \n",
      "B  2013-01-02 00:00:00  \n",
      "C                  1.0  \n",
      "D                    3  \n",
      "E                train  \n",
      "F                  foo  \n",
      "\n",
      "\n",
      "     F      E  D    C          B    A\n",
      "0  foo   test  3  1.0 2013-01-02  1.0\n",
      "1  foo  train  3  1.0 2013-01-02  1.0\n",
      "2  foo   test  3  1.0 2013-01-02  1.0\n",
      "3  foo  train  3  1.0 2013-01-02  1.0\n"
     ]
    }
   ],
   "source": [
    "df2 = pd.DataFrame({'A': 1.,\n",
    "                   'B': pd.Timestamp('20130102'),\n",
    "                   'C': pd.Series(1, index=list(range(4)), dtype='float32'),\n",
    "                   'D': np.array([3] * 4, dtype='int32'),\n",
    "                   'E': pd.Categorical([\"test\", \"train\", \"test\", \"train\"]),\n",
    "                   'F': 'foo'\n",
    "                   })\n",
    "print(df2)\n",
    "print(\"-\" * 20)\n",
    "print(df2.columns)\n",
    "print(df2.values)\n",
    "print(\"\\n\")\n",
    "print(np.transpose(df2))\n",
    "print(\"\\n\")\n",
    "print(df2.sort_index(axis=1, ascending=False))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "dc5481cb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "             A   B   C   D\n",
      "2025-01-01   0   1   2   3\n",
      "2025-01-02   4   5   6   7\n",
      "2025-01-03   8   9  10  11\n",
      "2025-01-04  12  13  14  15\n",
      "2025-01-05  16  17  18  19\n",
      "2025-01-06  20  21  22  23\n"
     ]
    }
   ],
   "source": [
    "dates = pd.date_range(\"2025.01.01\", periods=6)\n",
    "df3 = pd.DataFrame(np.arange(24).reshape((6, 4)), index=dates, columns=['A', 'B', 'C', 'D'])\n",
    "print(df3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "757053f3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "             A   C\n",
      "2025-01-01   0   2\n",
      "2025-01-02   4   6\n",
      "2025-01-03   8  10\n",
      "2025-01-04  12  14\n",
      "2025-01-05  16  18\n",
      "2025-01-06  20  22\n"
     ]
    }
   ],
   "source": [
    "print(df3.loc[:, ['A', 'C']])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "ba0503a7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "A    4\n",
      "B    5\n",
      "C    6\n",
      "D    7\n",
      "Name: 2025-01-02 00:00:00, dtype: int32\n",
      "------------------------------\n",
      "             B   C\n",
      "2025-01-04  13  14\n",
      "2025-01-05  17  18\n",
      "------------------------------\n",
      "            A  B   C   D\n",
      "2025-01-01  0  1   2   3\n",
      "2025-01-02  4  5   6   7\n",
      "2025-01-03  8  9  10  11\n",
      "------------------------------\n",
      "             A   B   C   D\n",
      "2025-01-05  16  17  18  19\n",
      "2025-01-06  20  21  22  23\n"
     ]
    }
   ],
   "source": [
    "print(df3.loc[\"2025.01.02\", :])  # loc base on label to select object\n",
    "print(\"-\" * 30)\n",
    "print(df3.iloc[3:5, 1:3])  # iloc base on position to select object\n",
    "print(\"-\" * 30)\n",
    "print(df3[0:3])\n",
    "print(\"-\" * 30)\n",
    "print(df3[(df3.A > 8) & (df3.B > 14)])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "8c648023",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "             A   B   C   D\n",
      "2025-01-01   0   1   2   3\n",
      "2025-01-02   4   5   6   7\n",
      "2025-01-03   8   9  10  11\n",
      "2025-01-04  12  13  14  15\n",
      "2025-01-05  16  17  13  19\n",
      "2025-01-06  20  21  22  23\n"
     ]
    }
   ],
   "source": [
    "df3.loc[\"2025.01.05\", 'C'] = 13\n",
    "print(df3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "edd7b231",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "             A   B     C     D\n",
      "2025-01-01   0   1   2.0   3.0\n",
      "2025-01-02   4   5   6.0   NaN\n",
      "2025-01-03   8   9   NaN  11.0\n",
      "2025-01-04  12  13  14.0  15.0\n",
      "2025-01-05  16  17  13.0  19.0\n",
      "2025-01-06  20  21  22.0  23.0\n"
     ]
    }
   ],
   "source": [
    "# insert some NaN\n",
    "df3.iloc[1, 3] = np.nan\n",
    "df3.iloc[2, 2] = np.nan\n",
    "print(df3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "cd4ea5e1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "             A   B     C     D\n",
      "2025-01-01   0   1   2.0   3.0\n",
      "2025-01-04  12  13  14.0  15.0\n",
      "2025-01-05  16  17  13.0  19.0\n",
      "2025-01-06  20  21  22.0  23.0\n"
     ]
    }
   ],
   "source": [
    "# pandas 处理丢失的数据\n",
    "df = df3.dropna(axis=0, how=\"any\")  # how = {\"any\", \"all\"}  any: 含有NaN， all：全是NaN\n",
    "print(df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "8f0cf591",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                A      B      C      D\n",
      "2025-01-01  False  False  False  False\n",
      "2025-01-02  False  False  False   True\n",
      "2025-01-03  False  False   True  False\n",
      "2025-01-04  False  False  False  False\n",
      "2025-01-05  False  False  False  False\n",
      "2025-01-06  False  False  False  False\n",
      "------------------------------\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "print(df3.isnull())\n",
    "print(\"-\" * 30)\n",
    "print(np.any(df3.isnull()) == True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "18e1c803",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "    Student ID  name   age  gender\n",
      "0         1100  Kelly   22  Female\n",
      "1         1101    Clo   21  Female\n",
      "2         1102  Tilly   22  Female\n",
      "3         1103   Tony   24    Male\n",
      "4         1104  David   20    Male\n",
      "5         1105  Catty   22  Female\n",
      "6         1106      M    3  Female\n",
      "7         1107      N   43    Male\n",
      "8         1108      A   13    Male\n",
      "9         1109      S   12    Male\n",
      "10        1110  David   33    Male\n",
      "11        1111     Dw    3  Female\n",
      "12        1112      Q   23    Male\n",
      "13        1113      W   21  Female\n"
     ]
    }
   ],
   "source": [
    "data = pd.read_csv(\"student.csv\")\n",
    "print(data)\n",
    "data.to_pickle(\"student.pickle\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "ee1bb3a7",
   "metadata": {},
   "outputs": [
    {
     "ename": "FileNotFoundError",
     "evalue": "[Errno 2] No such file or directory: 'C:\\\\Users\\\\25214\\\\Desktop\\\\抽卡记录.xlsx'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mFileNotFoundError\u001b[0m                         Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[13], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m data \u001b[38;5;241m=\u001b[39m \u001b[43mpd\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mread_excel\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mC:\u001b[39;49m\u001b[38;5;130;43;01m\\\\\u001b[39;49;00m\u001b[38;5;124;43mUsers\u001b[39;49m\u001b[38;5;130;43;01m\\\\\u001b[39;49;00m\u001b[38;5;124;43m25214\u001b[39;49m\u001b[38;5;130;43;01m\\\\\u001b[39;49;00m\u001b[38;5;124;43mDesktop\u001b[39;49m\u001b[38;5;130;43;01m\\\\\u001b[39;49;00m\u001b[38;5;124;43m抽卡记录.xlsx\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[0;32m      2\u001b[0m display(data)\n",
      "File \u001b[1;32m~\\AppData\\Local\\Programs\\Python\\Python38\\lib\\site-packages\\pandas\\io\\excel\\_base.py:478\u001b[0m, in \u001b[0;36mread_excel\u001b[1;34m(io, sheet_name, header, names, index_col, usecols, dtype, engine, converters, true_values, false_values, skiprows, nrows, na_values, keep_default_na, na_filter, verbose, parse_dates, date_parser, date_format, thousands, decimal, comment, skipfooter, storage_options, dtype_backend)\u001b[0m\n\u001b[0;32m    476\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(io, ExcelFile):\n\u001b[0;32m    477\u001b[0m     should_close \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mTrue\u001b[39;00m\n\u001b[1;32m--> 478\u001b[0m     io \u001b[38;5;241m=\u001b[39m \u001b[43mExcelFile\u001b[49m\u001b[43m(\u001b[49m\u001b[43mio\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstorage_options\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstorage_options\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mengine\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mengine\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m    479\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m engine \u001b[38;5;129;01mand\u001b[39;00m engine \u001b[38;5;241m!=\u001b[39m io\u001b[38;5;241m.\u001b[39mengine:\n\u001b[0;32m    480\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\n\u001b[0;32m    481\u001b[0m         \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mEngine should not be specified when passing \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m    482\u001b[0m         \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124man ExcelFile - ExcelFile already has the engine set\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m    483\u001b[0m     )\n",
      "File \u001b[1;32m~\\AppData\\Local\\Programs\\Python\\Python38\\lib\\site-packages\\pandas\\io\\excel\\_base.py:1496\u001b[0m, in \u001b[0;36mExcelFile.__init__\u001b[1;34m(self, path_or_buffer, engine, storage_options)\u001b[0m\n\u001b[0;32m   1494\u001b[0m     ext \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mxls\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m   1495\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m-> 1496\u001b[0m     ext \u001b[38;5;241m=\u001b[39m \u001b[43minspect_excel_format\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m   1497\u001b[0m \u001b[43m        \u001b[49m\u001b[43mcontent_or_path\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mpath_or_buffer\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstorage_options\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstorage_options\u001b[49m\n\u001b[0;32m   1498\u001b[0m \u001b[43m    \u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m   1499\u001b[0m     \u001b[38;5;28;01mif\u001b[39;00m ext \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[0;32m   1500\u001b[0m         \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\n\u001b[0;32m   1501\u001b[0m             \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mExcel file format cannot be determined, you must specify \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m   1502\u001b[0m             \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124man engine manually.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m   1503\u001b[0m         )\n",
      "File \u001b[1;32m~\\AppData\\Local\\Programs\\Python\\Python38\\lib\\site-packages\\pandas\\io\\excel\\_base.py:1371\u001b[0m, in \u001b[0;36minspect_excel_format\u001b[1;34m(content_or_path, storage_options)\u001b[0m\n\u001b[0;32m   1368\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(content_or_path, \u001b[38;5;28mbytes\u001b[39m):\n\u001b[0;32m   1369\u001b[0m     content_or_path \u001b[38;5;241m=\u001b[39m BytesIO(content_or_path)\n\u001b[1;32m-> 1371\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m \u001b[43mget_handle\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m   1372\u001b[0m \u001b[43m    \u001b[49m\u001b[43mcontent_or_path\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mrb\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstorage_options\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstorage_options\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mis_text\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\n\u001b[0;32m   1373\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m \u001b[38;5;28;01mas\u001b[39;00m handle:\n\u001b[0;32m   1374\u001b[0m     stream \u001b[38;5;241m=\u001b[39m handle\u001b[38;5;241m.\u001b[39mhandle\n\u001b[0;32m   1375\u001b[0m     stream\u001b[38;5;241m.\u001b[39mseek(\u001b[38;5;241m0\u001b[39m)\n",
      "File \u001b[1;32m~\\AppData\\Local\\Programs\\Python\\Python38\\lib\\site-packages\\pandas\\io\\common.py:868\u001b[0m, in \u001b[0;36mget_handle\u001b[1;34m(path_or_buf, mode, encoding, compression, memory_map, is_text, errors, storage_options)\u001b[0m\n\u001b[0;32m    859\u001b[0m         handle \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mopen\u001b[39m(\n\u001b[0;32m    860\u001b[0m             handle,\n\u001b[0;32m    861\u001b[0m             ioargs\u001b[38;5;241m.\u001b[39mmode,\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m    864\u001b[0m             newline\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[0;32m    865\u001b[0m         )\n\u001b[0;32m    866\u001b[0m     \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m    867\u001b[0m         \u001b[38;5;66;03m# Binary mode\u001b[39;00m\n\u001b[1;32m--> 868\u001b[0m         handle \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mopen\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mhandle\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mioargs\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmode\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m    869\u001b[0m     handles\u001b[38;5;241m.\u001b[39mappend(handle)\n\u001b[0;32m    871\u001b[0m \u001b[38;5;66;03m# Convert BytesIO or file objects passed with an encoding\u001b[39;00m\n",
      "\u001b[1;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: 'C:\\\\Users\\\\25214\\\\Desktop\\\\抽卡记录.xlsx'"
     ]
    }
   ],
   "source": [
    "# data = pd.read_excel(\"C:\\\\Users\\\\25214\\\\Desktop\\\\抽卡记录.xlsx\")\n",
    "# display(data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c3d90d81",
   "metadata": {},
   "outputs": [],
   "source": [
    "# data.iloc[8, :] = [\"铃纱\", 1, 0, 0, np.nan]\n",
    "# data.to_excel(\"C:\\\\Users\\\\25214\\\\Desktop\\\\抽卡记录.xlsx\", index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dc6df08e",
   "metadata": {},
   "outputs": [],
   "source": [
    "# data = pd.read_excel(\"C:\\\\Users\\\\25214\\\\Desktop\\\\抽卡记录.xlsx\")\n",
    "# display(data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "600e2b8b",
   "metadata": {},
   "outputs": [],
   "source": [
    "# pd.concat(objs, axis=0, join='outer', ignore_index=False, keys=None, levels=None, names=None, verify_integrity=False, sort=False)\n",
    "\"\"\"\n",
    "objs: 一个 list 或 dict，包含多个 DataFrame 或 Series，这些对象将被拼接。\n",
    "axis: 0 或 1。0 表示按行拼接（纵向拼接），1 表示按列拼接（横向拼接）。默认为 0。\n",
    "join: ‘outer’ 或 ‘inner’。指定如何处理合并时的索引对齐方式：\n",
    "‘outer’：取并集，默认行为，保留所有的索引（即使某些列/行不存在于某些 DataFrame 中）。\n",
    "‘inner’：取交集，只有在所有 DataFrame 中都有的列或行才会出现在结果中。\n",
    "ignore_index: bool，默认值为 False。如果为 True，则忽略原有的索引，并为新 DataFrame 分配新的整数索引。\n",
    "keys: list，默认为 None。如果传递了 keys，会将拼接的 DataFrame 按 keys 参数组合成层次化的索引。\n",
    "levels: 用于指定 keys 的层级信息。通常配合 keys 使用。\n",
    "names: 用于设置多层索引的名字。\n",
    "verify_integrity: bool，默认值为 False。如果为 True，检查拼接后的数据是否存在重复的索引。\n",
    "sort: bool，默认值为 False。如果为 True，则会对列进行排序。\n",
    "\"\"\"\n",
    "df1 = pd.DataFrame({'A': [1, 2]}, index=[0, 1])\n",
    "df2 = pd.DataFrame({'A': [3, 4]}, index=[3, 4])\n",
    "\n",
    "# 使用 ignore_index=True，重置索引\n",
    "result = pd.concat([df1, df2], ignore_index=True)\n",
    "\n",
    "print(result)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8ae61a92",
   "metadata": {},
   "outputs": [],
   "source": [
    "# pandas.merge(left, right, how='inner', on=None, left_on=None, right_on=None, left_index=False, right_index=False, sort=False, suffixes=('_x', '_y'), copy=True)\n",
    "\"\"\"\n",
    "left: 第一个 DataFrame，即左侧的 DataFrame。\n",
    "right: 第二个 DataFrame，即右侧的 DataFrame。\n",
    "how: 连接方式，支持以下几种方式：\n",
    "'inner'（默认）：交集，只保留两个 DataFrame 中都有的部分。\n",
    "'outer'：并集，保留两个 DataFrame 中的所有数据，缺失部分填充 NaN。\n",
    "'left'：左连接，保留左侧 DataFrame 的所有数据，右侧匹配不到的部分填充 NaN。\n",
    "'right'：右连接，保留右侧 DataFrame 的所有数据，左侧匹配不到的部分填充 NaN。\n",
    "on: 要连接的列名（如果两个 DataFrame 具有相同的列名）。如果两个 DataFrame 中连接列的名称不同，使用 left_on 和 right_on。\n",
    "left_on: 左侧 DataFrame 用来连接的列名（如果列名不同）。\n",
    "right_on: 右侧 DataFrame 用来连接的列名（如果列名不同）。\n",
    "left_index: bool，是否使用左侧 DataFrame 的索引作为连接键。默认 False。\n",
    "right_index: bool，是否使用右侧 DataFrame 的索引作为连接键。默认 False。\n",
    "sort: bool，是否对合并后的结果按连接键进行排序，默认为 False。\n",
    "suffixes: 用于为连接的列名称添加后缀，避免列名重复，默认值 ('_x', '_y')。\n",
    "\"\"\"\n",
    "import pandas as pd\n",
    "\n",
    "# 创建两个 DataFrame\n",
    "df1 = pd.DataFrame({\n",
    "    'ID': [1, 2, 3, 4],\n",
    "    'Name': ['Alice', 'Bob', 'Charlie', 'David']\n",
    "})\n",
    "\n",
    "df2 = pd.DataFrame({\n",
    "    'ID': [3, 4, 5, 6],\n",
    "    'City': ['New York', 'Los Angeles', 'Chicago', 'Houston']\n",
    "})\n",
    "\n",
    "# 使用 merge 进行内连接\n",
    "result = pd.merge(df1, df2, how='inner', on='ID')\n",
    "\n",
    "print(result)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "63eff33f",
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "data = pd.Series(np.random.randn(1000), index=np.arange(1000))\n",
    "data = data.cumsum()\n",
    "data.plot()\n",
    "\n",
    "print(\"-\" * 40)\n",
    "\n",
    "data = pd.DataFrame(np.random.randn(1000, 4),\n",
    "                   index=np.arange(1000),\n",
    "                   columns=list(\"ABCD\"))\n",
    "data = data.cumsum()\n",
    "print(data.head)\n",
    "data.plot()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "11b2f1d0",
   "metadata": {},
   "outputs": [],
   "source": [
    "data = pd.read_excel(\"C:\\\\Users\\\\25214\\\\Desktop\\\\2025年全国各专业招生计划.xlsx\")\n",
    "display(data[\"长江大学\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9e103176",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
